<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>块级元素居中</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: red;
            position: relative;
        }

        .child {
            width: 100px;
            height: 100px;
            background-color: green;
            margin: auto;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="child"></div>
</div>
</body>
</html>
